<template>
  <div class="custom-tabs">
    <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleTabClick">

      <!-- 对话 -->
      <el-tab-pane label="对话" name="chat" lazy="true">
        <RoleChatPanel ref="roleChatPanelRef" />
      </el-tab-pane>

      <!-- 知识图谱 -->
      <el-tab-pane label="知识图谱" name="graph">
        <div class="placeholder-content">
          知识图谱内容将显示在这里
        </div>
      </el-tab-pane>

      <!-- 笔记 -->
      <el-tab-pane label="笔记" name="notes">
        <div class="placeholder-content">
          笔记内容将显示在这里
        </div>
      </el-tab-pane>

      <!-- 改写 -->
      <el-tab-pane label="改写" name="rewrite">
        <div class="placeholder-content">
          知识图谱内容将显示在这里
        </div>
      </el-tab-pane>

    </el-tabs>
  </div>
</template>

<script setup>
import { ref, watch, nextTick } from 'vue';
import RoleChatPanel from './readerChatPanel.vue';

const props = defineProps({
  // 当前任务信息
  currentTaskInfo: {
    type: Object,
    default: () => ({})
  },

  // 当前场景信息
  currentSceneInfo: {
    type: Object,
    default: () => ({})
  }
});

const roleChatPanelRef = ref(null);
const activeName = ref('chat'); // 默认选中“对话”tab

// Element Plus tab 点击事件
const handleTabClick = (tab, event) => {
  console.log('选中标签页:', tab.props.name);
  // if (tab.props.name === 'chat' && props.currentSceneInfo.readerQueryAgentEngineer) {
  //   roleChatPanelRef.value?.openChatBoxWithRole(props.currentSceneInfo.readerQueryAgentEngineer);
  // }
};

// 监听父组件传入的 currentSceneInfo（异步数据）
watch(
  () => props.currentSceneInfo,
  (newVal) => {
    if (newVal && newVal.readerQueryAgentEngineer && activeName.value === 'chat') {
      nextTick(() => {
        roleChatPanelRef.value?.openChatBoxWithRole(newVal.readerQueryAgentEngineer);
      });
    }
  },
  { deep: true }
);

</script>

<style lang="scss" scoped>
.demo-tabs > .el-tabs__content {
  padding: 8px;
  color: #6b778c;
  font-size: 14px;
}

.placeholder-content {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: #999;
  font-size: 16px;
}

:deep(.el-tabs__item){
  height: 50px !important;
  font-weight: 550;
  color: #333 !important ; 
  font-size: 15px;
  font-family: HarmonyOS_Sans, PingFangSC-Regular, sans-serif, PingFangSC-Light, Microsoft YaHei, arial;
}

:deep(.el-tabs__nav-wrap:after){
  height: 1px !important;
}

</style>